package com.springstudy.shiro.shiro.filters;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.AccessControlFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 此拦截器用于判断是否登陆，只需subject.isAuthenticated或者subject.isRemembered其中一个为true即可
 *
 * @author chenrongrong
 * @since 2020/3/12 13:45
 */
@Slf4j
public class RememberFilter extends AccessControlFilter {
    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception {
        Subject subject = getSubject(servletRequest, servletResponse);
        if(subject.isAuthenticated() || subject.isRemembered()) {
            log.info("通过一般登陆校验");
            return true;
        }

        return false;
    }

    @Override
    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
        log.info("一般登陆校验失败");
        return false;
    }
}
